#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    int rob1(vector<int>& f)
    {
        int n = f.size();
        if (n == 0) return 0;
        vector<int> g(n);
        for (int i = 1; i < n; i++)
        {
            f[i] = g[i - 1] + f[i];
            g[i] = max(g[i - 1], f[i - 1]);
        }
        return max(f[n - 1], g[n - 1]);
    }
public:
    int rob(vector<int>& nums) {
        if (nums.size() == 1) return nums[0];
        vector<int> n1(nums.begin(), nums.end() - 1);
        vector<int> n2(nums.begin() + 1, nums.end());
        return max(rob1(n1), rob1(n2));
    }
};